 
   using System.Collections;
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Data;
   using HER;
  namespace FEL.COM
  {
  /// <summary>
  /// Acceso a los Web Services WS_COM
  /// Modulo: Compras ta
  /// Tabla: Com_Articulo
  /// </summary>
  [DataObject]
  public class BO_Com_Articulo
  {
  #region  Adapter
  private WS_COM _Adapter;
  /// <summary>
  /// Acceso al servicio
  /// </summary>
  public WS_COM Adapter
  {
  get
  {
  if (_Adapter == null)
  _Adapter = new WS_COM();
  return _Adapter;
  }
  }
  #endregion
  #region Obtención de datos
  
  [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
  public List<Com_Articulo> Get(string sortExpression, Scope s)
  {
  List<Com_Articulo> lista = new List<Com_Articulo>(Adapter.Com_Articulo_Get(s));
  lista.Sort(new Com_Articulo_Comparar(sortExpression));
  return lista;
  }
  // Retorna un data table de objetos
  [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
  public DataTable Get(Scope s)
  {
  return EntidadDT.GetDT(Adapter.Com_Articulo_Get(s));
  }
  
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo>GetByArticulos(string sortExpression, Scope s )
          {
          List<Com_Articulo> lista = new List<Com_Articulo> (Adapter.Com_Articulo_GetByArticulos(s));
          lista.Sort(new Com_Articulo_Comparar(sortExpression));
          return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetByArticulos(Scope s )
          {
          return EntidadDT.GetDT(Adapter.Com_Articulo_GetByArticulos(s));
          }
          
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo>GetByCodigo(string sortExpression, Scope s ,string Codigo )
          {
          List<Com_Articulo> lista = new List<Com_Articulo> (Adapter.Com_Articulo_GetByCodigo(s,  Codigo));
          lista.Sort(new Com_Articulo_Comparar(sortExpression));
          return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetByCodigo(Scope s ,string Codigo)
          {
          return EntidadDT.GetDT(Adapter.Com_Articulo_GetByCodigo(s,  Codigo));
          }
          
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo>GetById(string sortExpression, Scope s ,string Id )
          {
          List<Com_Articulo> lista = new List<Com_Articulo> (Adapter.Com_Articulo_GetById(s,  Id));
          lista.Sort(new Com_Articulo_Comparar(sortExpression));
          return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetById(Scope s ,string Id)
          {
          return EntidadDT.GetDT(Adapter.Com_Articulo_GetById(s,  Id));
          }
          
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo>GetByServicios(string sortExpression, Scope s  )
          {
          List<Com_Articulo> lista = new List<Com_Articulo> (Adapter.Com_Articulo_GetByServicios(s));
          lista.Sort(new Com_Articulo_Comparar(sortExpression));
          return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetByServicios(Scope s )
          {
          return EntidadDT.GetDT(Adapter.Com_Articulo_GetByServicios(s));
          }

          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo> GetByLikeNombreArticulos(string sortExpression, Scope s, string Nombre)
          {
              List<Com_Articulo> lista = new List<Com_Articulo>(Adapter.Com_Articulo_GetByLikeNombreArticulos(s, Nombre));
              lista.Sort(new Com_Articulo_Comparar(sortExpression));
              return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetByLikeNombreArticulos(Scope s, string Nombre)
          {
              return EntidadDT.GetDT(Adapter.Com_Articulo_GetByLikeNombreArticulos(s, Nombre));
          }

          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo> GetByGrupo(string sortExpression, Scope s, string Com_Grupo_Id, string Tipo)
          {
              List<Com_Articulo> lista = new List<Com_Articulo>(Adapter.Com_Articulo_GetByGrupo(s,Com_Grupo_Id,Tipo));
              lista.Sort(new Com_Articulo_Comparar(sortExpression));
              return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetByGrupo(Scope s, string Com_Grupo_Id, string  Tipo)
          {
              return EntidadDT.GetDT(Adapter.Com_Articulo_GetByGrupo(s, Com_Grupo_Id, Tipo));
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public List<Com_Articulo> GetByCentro(string sortExpression, Scope s,string Centro_Compra_Id, string Nombre)
          {
              List<Com_Articulo> lista = new List<Com_Articulo>(Adapter.Com_Articulo_GetByCentro(s,Centro_Compra_Id, Nombre));
              lista.Sort(new Com_Articulo_Comparar(sortExpression));
              return lista;
          }
          [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
          public DataTable GetByCentro(Scope s,string Centro_Compra_Id, string Nombre)
          {
              return EntidadDT.GetDT(Adapter.Com_Articulo_GetByCentro(s,Centro_Compra_Id, Nombre));
          }
          #endregion
  #region Operacion entre datos
  // Actualiza
  /// <summary>
  /// Actualiza la tabla Com_Articulo
  /// </summary>
  /// <param name="o">Objeto que contiene la informacion a actualizar</param>
  /// <returns></returns>
  /// <param name="original"></param>
  [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
  public int Update(Scope s,  Com_Articulo o, Com_Articulo original)
  {
  return Adapter.Com_Articulo_Update(s,o,original);
  }
  [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
  public int Update (Scope s, List<DictionaryEntry> parametros)
  {
  Com_Articulo o = new Com_Articulo();
  Com_Articulo original = new Com_Articulo();
  Navegacion.ObtenerObjetoYOriginalDeDiccionario(o, original, parametros);
  return Update(s,o, original);
  }
  // Inserta
  /// <summary>
  /// Inserta el objeto en Com_Articulo
  /// </summary>
  /// <param name="s"></param>
  /// <param name="o">Objeto a actualizar</param>
  /// <returns></returns>
  [DataObjectMethodAttribute(DataObjectMethodType.Insert, false)]
  public string Insert (Scope s, Com_Articulo o)
  {
  return Adapter.Com_Articulo_Insert(s , o);
  }
  [DataObjectMethodAttribute(DataObjectMethodType.Insert, false)]
  public string Insert(Scope s, List<DictionaryEntry>parametros)
  {
  Com_Articulo o = new Com_Articulo();
   Navegacion.ObtenerObjetoDeDiccionario(o, parametros);
  return Insert(s, o);
  }
  // Borra
  /// <summary>
  /// Borra el objeto en  Com_Articulo
  /// </summary>
  /// <param name="o">Objeto a borrar</param>
  /// <returns></returns>
  [DataObjectMethodAttribute(DataObjectMethodType.Delete, false)]
  public int Delete(Scope s,  Com_Articulo o)
  {
  return Adapter.Com_Articulo_Delete(s,o);
  }
  [DataObjectMethodAttribute(DataObjectMethodType.Delete, false)]
  public int Delete(Scope s, List<DictionaryEntry> parametros)
  {
  Com_Articulo original = new Com_Articulo();
   Navegacion.ObtenerOriginalDeDiccionario(original, parametros);
  return Delete(s,original);
  }
  #endregion
  #region Ordenar la lista
  class Com_Articulo_Comparar : IComparer<Com_Articulo>
  {
  private string _sortColumn;
  private bool _reverse;
  public Com_Articulo_Comparar(string sortExpression)
  {
  _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
  if (_reverse)
  _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
  else
  _sortColumn = sortExpression;
  }
  public int Compare( Com_Articulo x, Com_Articulo y)
  {
  int retVal = 0;
  switch (_sortColumn)
  {
  case "Id":
  retVal = string.Compare(x.Id, y.Id);
  break;
  case "Nombre":
  retVal = string.Compare(x.Nombre, y.Nombre);
  break;
  case "Codigo":
  retVal = string.Compare(x.Codigo, y.Codigo);
  break;
  case "Estado":
  retVal = string.Compare(x.Estado, y.Estado);
  break;
  }
  return (retVal * (_reverse ? -1 : 1));
  }
  }
  #endregion
    }
    }
